//------------Sonic CD Menu Control Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 3: TYPE_MENUCONTROL


function MenuControl_ChangeTrack
	switch Object[33].Frame
	case 0
				SetMusicTrack("JP/R1A.ogg",0,1)
		Object[32].Frame=0
		break
	case 1			
				SetMusicTrack("R1B.ogg",0,1)
		Object[32].Frame=33
		break
	case 2
				SetMusicTrack("JP/R1C.ogg",0,1)
		Object[32].Frame=11
		break
	case 3
				SetMusicTrack("JP/R1D.ogg",0,1)
		Object[32].Frame=22
		break
	case 4
				SetMusicTrack("JP/R3A.ogg",0,1)
		Object[32].Frame=0
		break
	case 5			
				SetMusicTrack("R3B.ogg",0,1)// Hybrid P+A
		Object[32].Frame=33
		break
	case 6
				SetMusicTrack("JP/R3C.ogg",0,1)
		Object[32].Frame=11
		break
	case 7
				SetMusicTrack("JP/R3D.ogg",0,1)
		Object[32].Frame=22
		break
	case 8
				SetMusicTrack("JP/R4A.ogg",0,1)
		Object[32].Frame=0
		break
	case 9			
				SetMusicTrack("R4B.ogg",0,1)
		Object[32].Frame=33
		break
	case 10
				SetMusicTrack("JP/R4C.ogg",0,1)
		Object[32].Frame=11
		break
	case 11
				SetMusicTrack("JP/R4D.ogg",0,1)
		Object[32].Frame=22
		break
	case 12
				SetMusicTrack("JP/R5A.ogg",0,1)
		Object[32].Frame=0
		break
	case 13
				SetMusicTrack("R5B.ogg",0,1)
		Object[32].Frame=33
		break
	case 14
				SetMusicTrack("JP/R5C.ogg",0,1)
		Object[32].Frame=11
		break
	case 15
				SetMusicTrack("JP/R5D.ogg",0,1)
		Object[32].Frame=22
		break
	case 16
				SetMusicTrack("JP/R6A.ogg",0,1)
		Object[32].Frame=0
		break
	case 17
				SetMusicTrack("R6B.ogg",0,1)// JP
		Object[32].Frame=33
		break
	case 18
				SetMusicTrack("JP/R6C.ogg",0,1)
		Object[32].Frame=11
		break
	case 19
				SetMusicTrack("JP/R6D.ogg",0,1)
		Object[32].Frame=22
		break
	case 20
				SetMusicTrack("JP/R7A.ogg",0,1)
		Object[32].Frame=0
		break
	case 21
				SetMusicTrack("R7B.ogg",0,1)
		Object[32].Frame=33
		break
	case 22
				SetMusicTrack("JP/R7C.ogg",0,1)
		Object[32].Frame=11
		break
	case 23
				SetMusicTrack("JP/R7D.ogg",0,1)
		Object[32].Frame=22
		break
	case 24
				SetMusicTrack("JP/R8A.ogg",0,1)
		Object[32].Frame=0
		break
	case 25
				SetMusicTrack("R8B.ogg",0,1)
		Object[32].Frame=33
		break
	case 26
				SetMusicTrack("JP/R8C.ogg",0,1)
		Object[32].Frame=11
		break
	case 27
				SetMusicTrack("JP/R8D.ogg",0,1)
		Object[32].Frame=22
		break
	case 28
				SetMusicTrack("JP/Boss.ogg",0,1)
		Object[32].Frame=0
		break
	case 29
				SetMusicTrack("JP/DAGarden.ogg",0,1)
		Object[32].Frame=0
		break
	case 30
				SetMusicTrack("JP/GameOver.ogg",0,0)
		Object[32].Frame=0
		break
	case 31
				SetMusicTrack("JP/ZoneComplete.ogg",0,0)
		Object[32].Frame=0
		break
	case 32
				SetMusicTrack("JP/Boss.ogg",0,1)
		Object[32].Frame=0
		break
	case 33
				SetMusicTrack("JP/Invincibility.ogg",0,0)
		Object[32].Frame=0
		break
	case 34
				SetMusicTrack("JP/SpeedShoes.ogg",0,0)
		Object[32].Frame=0
		break
	case 35
			SetMusicTrack("JP/TitleScreen.ogg",0,0)
		Object[32].Frame=0
		break
	case 36
				SetMusicTrack("JP/SpecialStage.ogg",0,1)
		Object[32].Frame=0
		break
	case 37
				SetMusicTrack("JP/Credits.ogg",0,1)
		Object[32].Frame=0
		break
	case 38
		switch SaveRAM[361]
			case 0
				SetMusicTrack("JP/Opening.ogg",0,1)
				break
			case 1
				SetMusicTrack("US/Opening.ogg",0,1)
				break
		endswitch
		Object[32].Frame=0
		break
	case 39
		switch SaveRAM[362]
			case 0
				SetMusicTrack("JP/Closing.ogg",0,1)
				break
			case 1
				SetMusicTrack("US/Closing.ogg",0,1)
			break
		endswitch
		Object[32].Frame=0
		break
	endswitch
	PlayMusic(SaveRAM[38])
endfunction


sub ObjectMain
	switch Object.State
	case 0
		Object.State=1
		Object.Value0=384
		SetScreenFade(0,0,0,255)
		PlayMusic(Options.Soundtrack)
		break
	case 1
		if Object.Value0>0
			Object.Value0-=8
		else
			Object.State=2
		endif
		SetScreenFade(0,0,0,Object.Value0)
		break
	case 2
		if KeyPress.Start==1
			StopMusic()
			Object.State=6
		endif
		if KeyPress.ButtonA==1
			Object.State=3
			Object[33].XPos=Screen.XSize
			Object[33].XPos+=96
			Object[33].XPos<<=16
			Object[33].State=1
			Object[33].DrawOrder=5
			Object[33].Priority=1
			Object[35].PropertyValue=4
			Object[36].PropertyValue=5
			Object[37].PropertyValue=6
		endif
		break
	case 3
		if Object[33].State==0
			if KeyPress.Left==1
				Object[33].State=4
			endif
			if KeyPress.Right==1
				Object[33].State=2
			endif
			if KeyPress.ButtonA==1
				Object.State=4
				StopMusic()
			endif
			if KeyPress.ButtonB==1
				Object.State=4
				StopMusic()
			endif
			if KeyPress.ButtonC==1
				Object.State=4
				StopMusic()
			endif
		endif
		if KeyPress.Start==1
			StopMusic()
			Object.State=6
		endif
		break
	case 4
		if Object.Value0<288
			Object.Value0+=8
		else
			Object[33].XPos=Screen.XSize
			Object[33].XPos+=96
			Object[33].XPos<<=16
			Object[33].State=0
			Object[33].Priority=0
			Object[35].PropertyValue=0
			Object[36].PropertyValue=2
			Object[37].PropertyValue=7
			CallFunction(MenuControl_ChangeTrack)
			Object.State++
		endif
		SetScreenFade(208,255,224,Object.Value0)
		break
	case 5
		if Object.Value0>0
			Object.Value0-=8
		else
			Object.State=2
		endif
		SetScreenFade(208,255,224,Object.Value0)
		break
	case 6
		if Object.Value0<384
			Object.Value0+=8
		else
			Stage.ListPos=1
			LoadStage()
		endif
		SetScreenFade(0,0,0,Object.Value0)
		break

	endswitch
endsub


sub ObjectStartup
	switch SaveRAM[38]
		case 0
			SetMusicTrack("JP/DAGarden.ogg",0,1)
			break
		case 1
			SetMusicTrack("US/DAGarden.ogg",1,117382)
			break
		case 2
			SetMusicTrack("JP/DAGarden.ogg",2,1)
			break
		case 3
			SetMusicTrack("US/DAGarden.ogg",3,117382)
			break
		case 4
			switch SaveRAM[360]
			case 0
				SetMusicTrack("JP/DAGarden.ogg",4,1)
				break
			case 1
				SetMusicTrack("US/DAGarden.ogg",4,117382)
				break
			endswitch
			break
		endswitch	
	Options.Soundtrack=SaveRAM[38]	
	Object[0].Type=TypeName[MenuControl]
	Object[0].DrawOrder=1
	Object[0].Priority=1
#platform: Standard
	Object[34].Type=TypeName[BlankObject]
	Object[35].Type=TypeName[BlankObject]
	Object[36].Type=TypeName[BlankObject]
	Object[37].Type=TypeName[BlankObject]
#endplatform
#platform: Mobile
	Object[34].DrawOrder=5
	Object[35].DrawOrder=5
	Object[36].DrawOrder=5
	Object[37].DrawOrder=5
	TempValue0=Screen.XSize
	TempValue0>>=2
	TempValue1=TempValue0
	TempValue1>>=1
	Object[34].iXPos=TempValue1
	TempValue1+=TempValue0
	Object[35].iXPos=TempValue1
	TempValue1+=TempValue0
	Object[36].iXPos=TempValue1
	TempValue1+=TempValue0
	Object[37].iXPos=TempValue1
#endplatform
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
